from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from config import Config
import redis
import pymysql

pymysql.install_as_MySQLdb()

db = SQLAlchemy()
migrate = Migrate()
redis_client = None


def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)

    db.init_app(app)
    migrate.init_app(app, db)

    global redis_client
    redis_client = redis.Redis(
        host=app.config["REDIS_HOST"],
        port=app.config["REDIS_PORT"],
        db=app.config["REDIS_DB"],
    )

    from . import views
    # models和scheduler模块在当前应用初始化中不需要显式导入
    # 如果后期需要在应用启动时初始化这些模块，请取消下面的注释
    # from . import models, scheduler

    views.init_app(app)

    # 已完全移除自动排班功能

    return app
